* tab1.do	JEP 	5/10/2015
* Builds table 1, sample sizes by mw incidence, city, formality , industry

*************************** Change log ********************************** 

/*
	
*/	

clear 
version 13.1

* Project info
cap project, doinfo
if _rc==198 {
	if c(os)=="Unix" loc master "/home/jperez/AA_Minimum_Wage" 
 else if c(username)=="J16339" loc master "B:\Col_Minimum_Wage"
 else if c(username)=="A15858" loc master "B:\Col_Minimum_Wage"
	else loc master "C:/Users/jorpp/Dropbox (Brown)/Col_Minimum_Wage"
	loc pr=0
}
else {
	local master "`r(pdir)'"
	local doname "`r(dofile)'" 
	* Project calls
	project, uses("`master'/Data/Source/ocupados_mw.dta")
	* Call programs
	project, relies_on("`master'/Code/Est/sample_choice.do")
	project, relies_on("`master'/Code/Est/build_mw_measures.do")
	project, relies_on("`master'/Code/Est/build_treatment.do")	
}
*/


* Call necessary programs. I do not call using project to carry the programs around. I do not put these in the ado/personal folder because they are specific to the project. They are not ado files.
do "`master'/Code/Est/sample_choice.do"
do "`master'/Code/Est/build_mw_measures.do"
do "`master'/Code/Est/build_treatment.do"

glo outdir "`master'/Doc/tosubmit2/tab"

* Draw graph for formal sector
use "`master'/Data/Source/ocupados_mw.dta", clear
graph drop _all
* Choose samples - get them from the estimates
mysample rif4sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) formal exind(13,29,42)
* est use "`master'/Ster/rif4new_ind/reg_ct_emp_bp_ixc_tq(1998q4)_bite_salario_mensual_real_50_edom_ind_p50.ster"
* replace rif4sample = rif4sample & e(sample)
mysample rif10sample , hmin(30) hmax(50) sex(0) edadm(65) wage(salario) informal exind(13,29,42)
* est clear 
* est use "`master'/Ster/rif10new_ind/reg_ct_emp_bp_ixc_tq(1998q4)_bite_salario_mensual_real_50_edom_ind_p50.ster"
* replace rif10sample = rif10sample & e(sample)
mw_measures rif4sample , stub(rif4)
mytreatment, posts("tq(1999q1)") mw(bite_rif4_ind) wage(salario_mensual_real)


keep if rif4sample | rif10sample 
count
* keep if time>=tq(1996q2)

gen wm=.
replace wm = 1 if salario_mensual_real < 0.97*minw_mensual_real
replace wm = 2 if salario_mensual_real >= 0.97*minw_mensual_real & salario_mensual_real<=1.03*minw_mensual_real
replace wm = 3 if salario_mensual_real > 1.03*minw_mensual_real

la define wmlab 1 "Below" 2 "At" 3 "Above"
la val wm wmlab
la var wm "Relative to Minimum Wage"


la var ciudad "City"
replace ciudad="BOGOTA" if ccode==2
replace ciudad="MEDELLIN" if ccode==6
replace ciudad=lower(ciudad)
replace ciudad=proper(ciudad)

gen f=.
replace f=1 if rif4sample
replace f=2 if rif10sample
la var f "Informality"
la define flab 1 "Formal" 2 "Informal"
la val f flab

/*
1 - Agriculture, Hunting, Forestry and Fishing
2 - Mining and Quarrying
3 - Manufacturing
4 - Electricity, Gas and Water
5 - Construction
6 - Wholesale and Retail Trade and Restaurants and Hotels
7 - Transport, Storage and Communication
8 - Financing, Insurance, Real Estate and Business Services
9 - Community, Social and Personal Services
0 - Activities not Adequately Defined
*/

gen cactividad_empresa_eng=cactividad_empresa
label define cactividad_empresa_eng 13 "Agriculture"
label define cactividad_empresa_eng 29 "Mining" , add
label define cactividad_empresa_eng 39 "Manufacturing" , add
label define cactividad_empresa_eng 42 "Utilities" , add
label define cactividad_empresa_eng 50 "Construction" , add
label define cactividad_empresa_eng 63 "Trade, Restaurants, Hotels" , add
label define cactividad_empresa_eng 72 "Transport and Communications" , add
label define cactividad_empresa_eng 83 "Financial services" , add
label define cactividad_empresa_eng 96 "Social and Personal Services" , add
                                      
la val cactividad_empresa_eng cactividad_empresa_eng
la var cactividad_empresa_eng "Industry"

* tabout f ciudad cactividad_empresa_eng wm using $outdir/formal_city_freq.tex [aw=fex] , c(row) topf($outdir/top.tex) botf($outdir/bot.tex) f(1c) /* layout(cb) */ style(tex) font(bold) bt  /* ptotal(none) */ replace npos(row) nlab(Sample size) cl1(2-4)

tabout f wm using $outdir/formal_city_freq.tex [aw=fex] , c(row) topf($outdir/top.tex) botf($outdir/bot.tex) f(1c) /* layout(cb) */ style(tex) font(bold) bt  /* ptotal(none) */ replace npos(row) nlab(Sample size) cl1(2-4)

*cd $outdir
*maketex using formal_city_freq.tex, packages(booktabs tabularx)
*!pdflatex  formal_city_freq.tex
*!formal_city_freq.pdf

// RELATIVE SIZE 

tab f [aw=fex]
